package com.wl4837;

public class Originator {

    private String state;

    public void setState(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }

    // 创建备忘录
    public Memento createMemento() {
        return new Memento(state);
    }

    // 从备忘录恢复状态
    public void restoreFromMemento(Memento memento) {
        this.state = memento.getState();
    }

    // 备忘录内部类
    public static class Memento {

        private final String state;

        public Memento(String state) {
            this.state = state;
        }

        public String getState() {
            return state;
        }

    }

}
